/*
 * File:   client_main.c
 * Author: Gordana
 *
 * Created on den 21 maj 2009, 15:36
 */


#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>     // sadrzi funkcije za rad za internet adresama

#include <string.h>
#include <pthread.h>

#include "message.h"

int main(int argc, char** argv) {
    int sockfd;
    struct sockaddr_in address;
    int result;
    int ip, port;
    char *ip_address;
    struct hostent *he;
    Message new_msg;

    sockfd = socket(PF_INET, SOCK_STREAM, 0); //  Kreiranje klijentskog socketa
    if (sockfd == -1) {
        perror("Socket create failed.\n");
        return -1;
    } else printf("Socket create OK");

    //port = Port();    // darija treba da napise funkcije
    //ip_address= Ip(); // -||-

    if ((he = gethostbyname("127.0.0.1")) == NULL) { // umesto 127.0.0.1. ip_address
        perror("gethostbyname()");
        exit(1);
    } else
        printf("Client-The remote host is: 127.0.0.1\n");

    address.sin_family = PF_INET; //Povezivanje na server
    address.sin_port = htons(3335);
    address.sin_addr = *((struct in_addr *) he->h_addr);
    memset(&(address.sin_zero), '\0', 8);
    // memset(&address, 0, sizeof(address));

    result = connect(sockfd, &address, sizeof (address));
    if (result == -1) {
        perror("Socket connection failed.\n");
        exit(-1);
    } else printf("Connection OK \n");


    //new_msg = Autentification();
   

        // Pocetak chat-a
    // chat(sockfd);
    return (EXIT_SUCCESS);
}

